package com.cate.mapper;

import com.cate.pojo.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    @Delete("delete from shopping_cart where id = #{id}")
    int deleteById(Long id);

    @Delete("delete from shopping_cart where user_id=#{userId}")
    int deleteByUserId(Long userId);

    /**
     * 添加购物车
     *
     * @param cart
     * @return
     */
    int insert(ShoppingCart cart);

    /**
     * 动态查询list
     *
     * @param cart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart cart);

    /**
     * 根据id修改商品数量
     *
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);


    /**
     * 批量插入购物车数据
     *
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
